﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Helpers.Converters
{
    public class NullOrEmptyStringToValue : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if ((value is string == false) && (value != null))
                return value;

            if ((value is string) && (string.IsNullOrEmpty(value.ToString()) == false))
                return value;

            return parameter;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (parameter.Equals(value))
                        ? null
                        : value;
        }
    }
}
